/* function TreeNode(x) {
    this.val = x;
    this.left = null;
    this.right = null;
} */
function IsBalanced_Solution(pRoot)
{
    // write code here
    if(pRoot === null) return true
    var leftDeep = TreeDeep(pRoot.left)
    var righttDeep = TreeDeep(pRoot.right)
    return Math.abs(righttDeep - leftDeep) <=1 && IsBalanced_Solution(pRoot.left)&&IsBalanced_Solution(pRoot.right)
}
function TreeDeep(root){
  if(root === null) return 0
  return TreeDeep(root.left) > TreeDeep(root.right) ? TreeDeep(root.left)+1 : TreeDeep(root.right)+1
}
module.exports = {
    IsBalanced_Solution : IsBalanced_Solution
};